﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QLVMBAYDomain;

namespace QLVMBAY.UControl
{
    public partial class UcLogin : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                pnLogin.Visible = Session[ClientComm.KEY_DANG_NHAP] == null;
                pnTTin.Visible  = Session[ClientComm.KEY_DANG_NHAP] != null;
                lblTitle.Text = Session[ClientComm.KEY_DANG_NHAP] == null ? "Đăng nhập" : "Thông tin cá nhân";
                if(Session[ClientComm.KEY_DANG_NHAP]!=null)
                {
                    lnkThayDoi.Text += ((NguoiDung)Session[ClientComm.KEY_DANG_NHAP]).MaNguoiDung;
                }
            }

        }

        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            var NguoiDung = ClientComm.Ints.NguoiDung.Login(txtTenDangNhap.Text, txtPass.Text);
            if (NguoiDung != null)
            {

                Session[ClientComm.KEY_DANG_NHAP] = NguoiDung;
                if (NguoiDung.LoaiND == QLVMBAYDomain.LOAI_NGUOI_DUNG.ADMIN)
                {
                    Response.Redirect("~/Admin/Default.aspx");
                }
                else
                {
                    Response.Redirect("~/Default.aspx");
                }

            }

        }

        protected void btnDangXuat_Click(object sender, EventArgs e)
        {
            Session[ClientComm.KEY_DANG_NHAP] = null;
            Response.Redirect("~/Default.aspx");
        }        
    }
}